//
//  ViewController.m
//  I18N-国际化
//
//  Created by J on 16/1/17.
//  Copyright © 2016年 J. All rights reserved.
//  iOS8种国际化需要在真机 模拟器无效
//  创建一个名字叫InfoPlist.string的文件改文件用于设置应用程序系统的一些文字(Xcode5会自动给我们创建,6开始手动创建)

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
//    UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
//    button.backgroundColor = [UIColor redColor];
//    button.frame = CGRectMake(100, 100, 100, 44);
//    [button addTarget:self action:@selector(change:) forControlEvents:UIControlEventTouchUpInside];
//    [self.view addSubview:button];
    
}
- (void)change:(UIButton*)button{
    if ((button.selected = !button.selected)) {
        button.backgroundColor = [UIColor orangeColor];

    }else{
        button.backgroundColor = [UIColor purpleColor];

    }
    
    //存储当前按钮选中状态
    //按钮选中状态作为标记
    NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
    
    [defaults setBool:button.selected forKey:@"selected"];
    
    
    
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
//  UIAlertView* alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"欢迎" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
//    [alert show];
    
    
    //根据当前系统语言取出对应语言的值
///  1.值对应的key 2.注视信息可以不写
    //会自动到系统的Localizable.strings文件中加载对应的数据
//    NSString* tips = NSLocalizedString(@"tips", nil);
//    NSString* message = NSLocalizedString(@"message", nil);
//    NSString* cancel = NSLocalizedString(@"cancel", nil);
//    NSString* ok = NSLocalizedString(@"ok", nil);
//
//    UIAlertView* alert = [[UIAlertView alloc]initWithTitle:tips message:message delegate:nil cancelButtonTitle:cancel otherButtonTitles:ok, nil];
//    [alert show];
    
    //从指定文件中加载多语言
    ///  1.值对应的key
//    2.指定的文件(保存了多语言键值对文件)
//    3.注视信息可以不写
    
//    NSString* localizableName = @"Localizable_XML";//从xml中加载多语言文件
    NSString* localizableName = nil;

    NSUserDefaults* defa = [NSUserDefaults standardUserDefaults];
    if ([defa objectForKey:@"selected"]) {
        localizableName = @"Localizable_CN";//Localizable_XML可以替换为xml解析 好处是可以直接回车换行
    }else{
        localizableName = @"Localizable_EN";

    }

        NSString* tips = NSLocalizedStringFromTable(@"tips",localizableName, nil);
        NSString* message = NSLocalizedStringFromTable(@"message",localizableName, nil);
        NSString* cancel = NSLocalizedStringFromTable(@"cancel",localizableName, nil);
        NSString* ok = NSLocalizedStringFromTable(@"ok",localizableName,nil);
    
        UIAlertView* alert = [[UIAlertView alloc]initWithTitle:tips message:message delegate:nil cancelButtonTitle:cancel otherButtonTitles:ok, nil];
        [alert show];
    
    
    
}






@end
